package logic

import (
	"context"
	"errors"
	"video-up-manager/models/mysql"

	"video-up-manager/videorpc/internal/svc"
	"video-up-manager/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoShowLogic {
	return &VideoShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *VideoShowLogic) VideoShow(in *videorpc.VideoShowRequest) (*videorpc.VideoShowResponse, error) {
	// todo: add your logic here and delete this line
	var video mysql.Video

	if err := video.FindVideoByTitle(mysql.DB, in.VideoId); err != nil {
		return nil, errors.New("视频不存在")
	}

	if err := video.VideoShow(mysql.DB, in.VideoId); err != nil {
		return nil, err
	}

	return &videorpc.VideoShowResponse{
		UploadUserId:  video.UploadUserId,
		VideoTitle:    video.VideoTitle,
		VideoCategory: video.VideoCategory,
		VideLink:      video.VideLink,
		CoverLink:     video.CoverLink,
		VideoIntro:    video.VideoIntro,
		PlayNum:       video.PlayNum,
		LikeNum:       video.LikeNum,
		CollectNum:    video.CollectNum,
		CommentNum:    video.CommentNum,
		ReleaseTime:   video.ReleaseTime,
		VideoStatus:   video.VideoStatus,
		TopicId:       video.TopicId,
		VideoDuration: video.VideoDuration,
	}, nil
}
